package com.lanou3g.farmdoctor.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.IntegerRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou3g.farmdoctor.R;
import com.lanou3g.farmdoctor.base.BaseActivity;
import com.lanou3g.farmdoctor.entity.greendao.RichDetailEntity;
import com.lanou3g.farmdoctor.fragment.RichItemFragment;
import com.lanou3g.farmdoctor.volley.VolleySingleton;

/**
 * 本类由: Risky 创建于: 15/11/26.
 */
public class ForRichDetailActivity extends BaseActivity implements View.OnClickListener{
    private static final String URL = "http://www.nongyisheng.com/article?id=";
    private String id;
    private int count;
    private WebView webView;
    private RichDetailEntity entity;
    private String url;
    private TextView tvBack,tvMiddle,tvComment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rich_detail);
        initView();
        intiData();
        webView.loadUrl(url);
//        VolleySingleton.addRequest(url, new Response.Listener<String>() {
//            @Override
//            public void onResponse(String response) {
//                Log.d("ForRichDetailActivity", response);
//                webView.loadData(response,"","utf-8");
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Log.d("ForRichDetailActivity", "error:" + error);
//            }
//        });
    }

    private void intiData() {
        entity = (RichDetailEntity) getIntent().getSerializableExtra(RichItemFragment.ARG_RICH_ITEM);
        id = entity.getId()+"";
        url = URL + id;
        Log.d("ForRichDetailActivity", url);
        count = Integer.parseInt(entity.getCmtcount());
        tvComment.setText(count+getString(R.string.rich_detail_comment));

    }

    private void initView() {
        tvBack = findView(R.id.tv_left);
        tvMiddle = findView(R.id.tv_middle);
        tvComment = findView(R.id.tv_right);
        tvBack.setText(R.string.rich_detail_back);
        tvBack.setOnClickListener(this);
        tvMiddle.setText(R.string.for_rich);
//        TextView tv = (TextView) toolbar.getChildAt(0);
//        tv.setText(R.string.for_rich);
        webView = findView(R.id.webView);
    }

    private void toast(RichDetailEntity entity){
        Toast.makeText(this,entity.getTitle(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View v) {
        finish();
    }
}
